<template>
  <!-- 添加或修改检阅信息对话框 -->
  <el-dialog
    title="我的检阅"
    :visible.sync="open"
    width="680px"
    height="400px;"
    :before-close="handleCloseDialog"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="检阅人" prop="ctUsername">
        <el-input v-model="form.ctUsername" placeholder="检阅人" disabled />
      </el-form-item>
      <el-form-item label="检阅日期" prop="dtDate">
        <el-input v-model="form.dtDate" placeholder="检阅日期" disabled />
      </el-form-item>
      <el-form-item label="检阅组织" prop="ctBranchname">
        <el-input v-model="form.ctBranchname" placeholder="请输入检阅人单位名称" disabled />
      </el-form-item>
      <el-form-item label="检阅意见" prop="ctComment">
        <el-input
          v-model="form.ctComment"
          type="textarea"
          placeholder="请选择或输入检阅意见"
          rows="4"
          resize="none"
        />
        <el-radio-group v-model="selectValue" @change="changeRadioVal">
          <el-radio label="已阅">已阅</el-radio>
          <el-radio label="很好,继续努力">很好,继续努力</el-radio>
          <el-radio label="不够完善,望加强">不够完善,望加强</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注说明" prop="ctMark">
        <el-input v-model="form.ctMark" type="textarea" rows="4" resize="none" placeholder="备注说明" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">关 闭</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addReview, updateReview } from './ReviewList'
import { parseTime } from '@/utils/ruoyi'
export default {
  name: 'AddReview',
  props: {
    dialogFormData: {
      Type: Object,
      default: () => {
        return {}
      },
    },
  },
  data() {
    return {
      //获取爷爷的内容
      grandFather: this.$parent.$parent.$parent,
      //功能号 = 到底用props 还是这种？
      funNo: null,
      //业务单号
      bussId: null,
      //选择值
      selectValue: '已阅',
      // 遮罩层
      loading: true,
      // 是否显示弹出层
      open: false,

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ctComment: [
          {
            required: true,
            message: '检阅意见必须选择或输入',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  created() {},
  methods: {
    handleOpenDialog() {
      // //设置爷爷级别的激活标签
      // this.grandFather.activeTab = 'tabReviews'
      // //获取爷爷级别的功能号
      // this.funNo = this.grandFather.funNo
      // //获取爷爷的业务单号
      // this.bussId = this.grandFather.bussId
      //当前页面展示出来！
      this.open = true
      //清空
      this.reset()
      //初始化
      this.initForm()
    },
    handleCloseDialog() {
      this.open = false
    },

    //初始化默认值等
    initForm() {
      //检阅意见
      this.selectValue = '已阅'
      this.form['ctComment'] = this.selectValue
      this.form['dtDate'] = parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}')
      // //检阅部门代码
      // this.form['ctBranchcode'] = this.$store.state.user.dept.deptId
      // //检阅部门名称
      this.form['ctBranchname'] = this.$store.state.user.dept.deptName
      // //业务编码
      // this.form['ctBussId'] = ""
      // //用户信息
      // this.form['ctUsercode'] = this.$store.state.user.name
      this.form['ctUsername'] = this.$store.state.user.nickName
      // //功能号
      // this.form['ctFunNo'] = ""
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        ctId: null,
        ctBussId: null,
        ctFunNo: null,
        dtDate: null,
        ctUsercode: null,
        ctUsername: null,
        ctBranchcode: null,
        ctBranchname: null,
        ctComment: null,
        ctMark: null,
        ctOther1: null,
        ctOther2: null,
        ctOther3: null,
      }
      this.resetForm('form')
    },

    /** 提交按钮 */
    submitForm() {
      this.form['ctFunNo'] = this.dialogFormData.selectedCt.ct_fun_no
      this.form['ctBussId'] = this.dialogFormData.selectedCt.ct_id

      this.$refs['form'].validate((valid) => {
        if (valid) {
          //校验数据并保存！
          addReview(this.form)
            .then((response) => {
              this.msgSuccess('检阅成功')
              this.open = false
              //新增成功，则刷新数据
              this.$emit('refreshReviewList')
            })
            .catch((res) => {
              this.updateLoading = false
            })
        }
      })
    },
    //radio 更新
    changeRadioVal(value) {
      this.form['ctComment'] = value
    },
  },
}
</script>
